//
//  UIBarButtonItem+Extension.swift
//  SinaWeibo
//
//  Created by 张晗 on 2017/2/7.
//  Copyright © 2017年 zhanghan. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.black, hightlightedColor: UIColor.orange)
        if isBack {
            btn.setImage(#imageLiteral(resourceName: "navigationbar_back_withtext"), for: .normal)
            btn.setImage(#imageLiteral(resourceName: "navigationbar_back_withtext_highlighted"), for: .highlighted)
            btn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0)
            btn.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0)
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        self.init(customView:btn)
    }
}
